#include"Commond.h"
#include"CentralCache.h"
#include"ThreadCache.h"
#include"ConcurrnetAlloc.h"
using namespace std;
void TextConcurrentAlloc()
{
	void* p1 = ConcurrentAlloc(6);
	void* p2 = ConcurrentAlloc(6);
	void* p3 = ConcurrentAlloc(6);
	void* p4 = ConcurrentAlloc(6);
	cout << "p1=" << p1 << std::endl;
	cout << "p2=" << p2 << std::endl;
	cout << "p3=" << p3 << std::endl;
	cout << "p4=" << p4 << std::endl;
}
void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 2; ++i)
	{
		void* ptr = ConcurrentAlloc(MAX_BYTES+1);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		cout << e << std::endl;
		ConcurrentFree(e, 6);
	}
}
void MultiThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 100; ++i)
	{
		void* ptr = ConcurrentAlloc(16);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		cout << e << std::endl;
		ConcurrentFree(e, 16);
	}
}
void MultiThreadAlloc()
{
	std::thread t1(MultiThreadAlloc1);
	//std::thread t2(MultiThreadAlloc2);

	t1.join();
	//t2.join();
}
//int main()
//{
//	//TextConcurrentAlloc();
//	MultiThreadAlloc1();
//	return 0;
//}